'use strict';

App.controller('myBidsController', ['$rootScope', '$scope', '$state', 'Page', function($rootScope, $scope, $state, Page) {
	$scope.bidQuery = {};
	$scope.customerId =	$rootScope.user.sourceId;// 根据登录用户获得客户id
	if($scope.customerId == '' || $scope.customerId == null){
		$state.go('login', null);
		Page.notice("获取登录信息失败!");
		return;
	}
	
	
	$scope.bidTable = {
			query : function() {
				var param = {};
				param.customerId = $scope.customerId;
				param.bidCode = $scope.bidQuery.bidCode;
				param.pageIndex = 0;
				param.pageSize = 10;
				Page.ajaxPost('www/bid/getCustomerBidsInfo.do', param, function (resp) {
					 $scope.bidArray = resp.data.dataArray;
					 
					// 调用分页
				    	$scope.totalPages = resp.data.totalPages;
						laypage({
							cont : 'page_bar',
							pages : $scope.totalPages,// 得到总页数
							skin : '#12bdce',
							skip : true, // 是否开启跳页
							prev : '<', // 若不显示，设置false即可
							next : '>', // 若不显示，设置false即可
							groups : 5, //连续分页数
							curr: 1, //初始化当前页
							jump : function(obj,first) {// 触发分页后的回调
								/*obj是一个object类型。包括了分页的所有配置信息。
								 first一个Boolean类，检测页面是否初始加载。非常有用，可避免无限刷新。*/
								if(!first){
									param.pageIndex = obj.curr - 1;
									Page.ajaxPost('www/bid/getCustomerBidsInfo.do', param, function(resp) {
										$scope.bidArray = resp.data.dataArray;
										$scope.totalPages = resp.data.totalPages;
									});
								}
							}
						})
				 });
			},
			viewBidRecordInfo : function(data) {
				$scope.bid = data;
				$scope.bidRecordArray = $scope.bid.bidRecordArray;
				$scope.bidRecordModal.show();
			}
			
	}
	$scope.bidTable.query();
	
	$scope.bidRecordModal = {
			onShow : function(){
				this.setTitle('出价记录 -- ' +$scope.bid.bidTitle);
			},
			onOkClick : function() {
				$scope.bidRecordModal.hide();
			}
	}
	
}]);